(function(){
    var app = angular.module("sepai",['ngAnimate']);

    app.animation('.mark',function(){
        return{
            enter: function(element,done){
                //jQuery(element).fadeIn(800);
                jQuery('html, body').animate({
                    'scrollTop' : jQuery(element).position().top - 180
                });
                $(".carousal").carousal();
                $(".tl-main li").position();
                done;
            },
            leave: function(element,done){
            }
        };
    });
    
    app.directive('viewIndividual', function() {
        return function(scope, element, attrs) {
            element.on('click', function() {
                element.viewIndividual();
            });
        };
     });

    app.directive('readMore', function() {
        return function(scope, element, attrs) {
            element.on('click', function() {
                element.readMore();
            });
        };
     });

    app.directive('closeTarget', function() {
        return function(scope, element, attrs) {
            element.on('click', function() {
                element.closeTarget();
            });
        };
    });
    
    app.directive('minimenuControl', function() {
        return function(scope, element, attrs) {
            element.on('click', function() {
                element.menuControl();
            });
        };
    });

    app.directive('carousalController', function() {
        return function(scope, element, attrs) {
            element.on('click', function() {
                element.carousalSlide();
            });
        };
    });

    app.directive('dramaDetails', function() {
        return function(scope, element, attrs) {
            element.on('click', function() {
                element.detailView();
            });
        };
    });
    
    app.directive('backDetails', function() {
        return function(scope, element, attrs) {
            element.on('click', function() {
                element.backFromDetailView();
            });
        };
    });
    
    app.controller('DramaController',['$http','$scope',function($http,$scope){
        var dramaList = this;
        dramaList.notice = [];

        $http.get("JSON/SEPAIHistory.js").success(function (data) {
            dramaList.drama = data;
        });
        
        $scope.timeLeft = function(date){
            var oneDay = 24*60*60*1000;
            var t = new Date();
            var d = new Date(date);
            
            var diffDays = ( d.getTime() - t.getTime())/(oneDay);
            if(diffDays < 0){
                diffDays = "Latest Production";
            }else if(diffDays <=1){
                diffDays = Math.round(diffDays * 24) + " Hours";
            }else{
                diffDays = Math.round(diffDays) + " Days";
            }
            
            return diffDays;
        };
    }]);

    
})();